<?php
/**
 * BootAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using BootAdmin.
 *
 * @Author G.r<root@BootAdmin.com>
 */

declare (strict_types=1);

namespace app\admin;

use app\BaseController;

class Base extends BaseController
{
    /**
     * 无需登录的方法
     * @var array
     */
    public array $notNeedLogin = [];

    /**
     * 无需鉴权的方法
     * @var array
     */
    public array $notNeedRight = [];

    protected int $adminId = 0;
    protected array $adminInfo = [];

    /**
     * 初始化
     */
    public function initialize()
    {
        if (isset($this->request->adminInfo) && $this->request->adminInfo) {
            $this->adminInfo = $this->request->adminInfo;
            $this->adminId = $this->request->adminInfo['id'];
        }
    }

    /**
     * 是否免登录验证
     * @return bool
     */
    public function isNotNeedLogin() : bool
    {
        $notNeedLogin = $this->notNeedLogin;
        if (empty($notNeedLogin)) {
            return false;
        }
        return action_in_arr($notNeedLogin);
    }

    /**
     * 是否免权限验证
     * @return bool
     */
    public function isNotNeedAuth() : bool
    {
        $notNeedRight = $this->notNeedRight;
        if (empty($notNeedRight)) {
            return false;
        }
        return action_in_arr($notNeedRight);
    }
}